package com.rdd.wordcount

import org.apache.spark.{SparkConf, SparkContext}

object WordCount {

  def main(args: Array[String]) {
    val conf = new SparkConf().setAppName("WordCount").setMaster("local");
    val sc = new SparkContext(conf)

    val lines = sc.textFile("e:\\aaa.txt", 1);
//    val words = lines.flatMap { line => line.split(" ")}

    val words = lines.flatMap(_.split(" "))

    val pairs = words.map {word => (word, 1)}
    val wordCount = pairs.reduceByKey(_ + _)
    wordCount.foreach(wordCount => println(wordCount._1 + " appeared " + wordCount._2 + " times"))
  }
}
